# !/usr/bin/env python
# _*_ coding:utf-8 _*_


import pickle
import json
import base64



class CookieSecret(object):
    @classmethod
    def dumps(cls, data):
        data_bytes = pickle.dumps(data)
        base64_bytes = base64.b64encode(data_bytes)
        return base64_bytes.decode()

    @classmethod
    def loads(cls, data):
        base64_decode = base64.b64decode(data)
        pickle_result = pickle.loads(base64_decode)
        return pickle_result

    #
    # if __name__ == '__main__':
    #
    #     # json str<-->dict(list)
    #     data_dict = {
    #         1:"a"
    #     }
    #
    #     json_str = json.dumps(data_dict)
    #     json_dict = json.loads(json_str)
    #
    #
    #     # pickle  Python数据类型<-->bytes
    #     pickle_bytes = pickle.dumps(data_dict)
    #     pickle_dict = pickle.loads(pickle_bytes)
    #
    #     # base64 编解码
    #     base64_bytes = base64.b64encode(pickle_bytes)
    #     base64_decode = base64.b64decode(base64_bytes)
    #     result = pickle.loads(base64_decode)
    #     print(base64_bytes)
    #     print(base64_decode)
    #     print(result)
